import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:getwidget/components/avatar/gf_avatar.dart';
import 'package:getwidget/components/checkbox_list_tile/gf_checkbox_list_tile.dart';
import 'package:getwidget/components/sticky_header/gf_sticky_header.dart';
import 'package:getwidget/types/gf_checkbox_type.dart';

import '../controllers/gfstickyheader_controller.dart';

class GfstickyheaderView extends GetView<GfstickyheaderController> {
  List imageList = [
    'assets/images/flutter.jpg', 
    'assets/images/bg_drawer.jpg',
  ];
  String avatarPath = 'assets/images/cliu.jpg';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('吸顶头部'),
        centerTitle: true,
      ),
      body: Container(
        margin: EdgeInsets.all(10),
        child: ListView.builder(
          itemCount: imageList.length,
          itemBuilder: (context, index) => GFStickyHeader(
            stickyContent: Container(
              child: Container(
                alignment: AlignmentDirectional.center,
                height: 50,
                width: Get.width,
                color: Color(0xFF60517B),
                padding: EdgeInsets.symmetric(horizontal: 16.0),
                child: Row(
                  children: [
                    Text(
                      'Contact Group $index',
                      style: const TextStyle(color: Colors.white),
                    ),
                  ],
                ),
              ),
            ),
            content: Container(
              height: 300,
              child: ListView.builder(
                physics: ScrollPhysics(),
                shrinkWrap: true,
                scrollDirection: Axis.vertical,
                itemCount: 8,
                itemBuilder: (BuildContext context, int index) {
                  return SingleChildScrollView(
                    child: Column(
                      children: [
                        Obx(() {
                          return GFCheckboxListTile(
                            titleText: '初六',
                            subTitleText: '懂二进制的男人',
                            avatar: GFAvatar(
                              backgroundImage: AssetImage(avatarPath),
                            ),
                            size: 25,
                            activeBgColor: Colors.green,
                            activeIcon: Icon(
                              Icons.check,
                              size: 15,
                              color: Colors.white,
                            ),
                            type: GFCheckboxType.circle,
                            onChanged: (val) {
                              print(val);
                              controller.isChecked.value = val;
                            },
                            value: controller.isChecked.value,
                            inactiveIcon: null,
                          );
                        }),
                        Padding(
                          padding: const EdgeInsets.symmetric(horizontal: 20.0),
                          child: Divider(),
                        ),
                      ],
                    ),
                  );
                }
              ),
            )
          )
        )
      )
    );
  }
}
